/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package data;

import connection.Account;
import connection.IReceiver;
import data.email.EmailFolder;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.SwingWorker;

/**
 *
 * @author Arcanis
 */
public class LoadMailsWorker extends SwingWorker<List<EmailFolder>, Object> {

    private Set<EmailFolder> folder;
    private AccountData data;
    private Data data1;

    public LoadMailsWorker(Set<EmailFolder> folder, AccountData data, Data data1) {
        this.folder = folder;
        this.data = data;
        this.data1 = data1;
    }

    @Override
    protected List<EmailFolder> doInBackground() throws Exception {
        Account a = Account.createAccount(this.data);
        List<EmailFolder> lf = ((IReceiver) a).loadAllFolders();
        return lf;
    }

    @Override
    protected void done() {
        try {
            data1.setFolders(get());
        } catch (InterruptedException | ExecutionException ex) {
            Logger.getLogger(LoadMailsWorker.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
